package com.xx.eshop.service.impl;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.xx.eshop.dao.AttrDao;
import com.xx.eshop.dao.AttrValueDao;
import com.xx.eshop.entity.Attr;
import com.xx.eshop.entity.AttrValue;
import com.xx.eshop.service.AttrService;

@Service
@Transactional
public class AttrServiceImpl implements AttrService{
	
	@Autowired
	private AttrDao attrDao;
	
	@Autowired
	private AttrValueDao valueDao;

	
	@Override
	public Attr updateSort(int attrId, int attrSort) {
		Attr attr = attrDao.findOne(attrId);
		System.out.println("====service 中："+attr.toString());
		attr.setSort(attrSort);
		attrDao.update(attr);
		return attr;
		
	}
	
	public void delete(int id){
		// 根据属性ID查到该属性对应的所有属性值
		List<AttrValue> valueList = valueDao.findByAttr(id);
		for(AttrValue v:valueList){
			valueDao.delete(v.getId());
		}
		attrDao.delete(id);
	}
	
	
	public void update(Attr attr){
		 attrDao.update(attr);
	}
	
	@Override
	public List<Attr> findByCategory(int cid) {
		return attrDao.findByCategory(cid);
	}

	@Override
	public List<AttrValue> findByAttr(int aid) {
		return valueDao.findByAttr(aid);
	}
	
	@Override
	public List<Attr> findByCategoryFetch(int cid) {
		return attrDao.findByCategoryFetch(cid);
	}
	


	
	public Attr findOne(int id){
		return attrDao.findOne(id);
	}

	@Override
	public void save(Attr attr) {
		attrDao.save(attr);
	}

	

	

}
